<?php
class MY_Controller extends CI_Controller{
	
	function __construct(){
		parent::__construct();
	}
		
	protected function finalizeView($config){
		$this->load->view('dashboard/main/finalizeView/dashboard',$config);
	}
	
	protected function finalizeViewAdmin($config){
		$this->load->view('dashboard/admin/finalizeView/dashboard',$config);
	}
	
	/**
	 * router signature call function from ajax request
	 * @param unknown_type $func_name
	 */
	function ajax($func_name, $a=false, $b=false, $c=false, $d=false){
		$this->{'_'.$func_name}($a, $b, $c, $d);
	}
	
	protected function images_large($picture_tmp,$size,$picture_name,$picture_type){
		switch($picture_type){
			case "image/jpeg": 
				$pic = imagecreatefromjpeg($picture_tmp);
				$width_comp  = imagesx( $pic );
				$height_comp  = imagesy( $pic );
				$new_width_comp = $size;
				$new_height_comp  = floor( $height_comp * ( $size / $width_comp  ) );
				$tmp_img_comp  = imagecreatetruecolor( $new_width_comp , $new_height_comp  );
				$up_comp  = imagecopyresized( $tmp_img_comp , $pic, 0, 0, 0, 0, $new_width_comp , $new_height_comp , $width_comp , $height_comp  );
				$pth_comp  = site_url("images/temp/$picture_name");
				ob_start();
				$inp_comp  = imagejpeg( $tmp_img_comp  );
				$create_images_large = ob_get_contents();	
				return $create_images_large;
			break;
			case "image/png": 
				$pic = imagecreatefrompng($picture_tmp);
				$width_comp  = imagesx( $pic );
				$height_comp  = imagesy( $pic );
				$new_width_comp = $size;
				$new_height_comp  = floor( $height_comp * ( $size / $width_comp  ) );
				$tmp_img_comp  = imagecreatetruecolor( $new_width_comp , $new_height_comp  );
				$up_comp  = imagecopyresized( $tmp_img_comp , $pic, 0, 0, 0, 0, $new_width_comp , $new_height_comp , $width_comp , $height_comp  );
				$pth_comp  = site_url("images/temp/$picture_name");
				ob_start();
				$inp_comp  = imagepng( $tmp_img_comp  );
				$create_images_large = ob_get_contents();	
				return $create_images_large;
			break;
			case "image/bmp": 
				$pic = imagecreatefromjpeg($picture_tmp);
				$width_comp  = imagesx( $pic );
				$height_comp  = imagesy( $pic );
				$new_width_comp = $size;
				$new_height_comp  = floor( $height_comp * ( $size / $width_comp  ) );
				$tmp_img_comp  = imagecreatetruecolor( $new_width_comp , $new_height_comp  );
				$up_comp  = imagecopyresized( $tmp_img_comp , $pic, 0, 0, 0, 0, $new_width_comp , $new_height_comp , $width_comp , $height_comp  );
				$pth_comp  = site_url("images/temp/$picture_name");
				ob_start();
				$inp_comp  = imagewbmp( $tmp_img_comp  );
				$create_images_large = ob_get_contents();	
				return $create_images_large;
			break;
			case "image/gif": 
				$pic = imagecreatefromgif($picture_tmp);
				$width_comp  = imagesx( $pic );
				$height_comp  = imagesy( $pic );
				$new_width_comp = $size;
				$new_height_comp  = floor( $height_comp * ( $size / $width_comp  ) );
				$tmp_img_comp  = imagecreatetruecolor( $new_width_comp , $new_height_comp  );
				$up_comp  = imagecopyresized( $tmp_img_comp , $pic, 0, 0, 0, 0, $new_width_comp , $new_height_comp , $width_comp , $height_comp  );
				$pth_comp  = site_url("images/temp/$picture_name");
				ob_start();
				$inp_comp  = imagegif( $tmp_img_comp  );
				$create_images_large = ob_get_contents();	
				return $create_images_large;
			break;
		}
	}
	
	protected function images_medium($picture_tmp,$size,$picture_name,$picture_type){
		switch($picture_type){
			case "image/jpeg":
				$pic = imagecreatefromjpeg($picture_tmp);
				$width_comp  = imagesx( $pic );
				$height_comp  = imagesy( $pic );
				$new_width_comp = $size;
				$new_height_comp  = floor( $height_comp * ( $size / $width_comp  ) );
				$tmp_img_comp  = imagecreatetruecolor( $new_width_comp , $new_height_comp  );
				$up_comp  = imagecopyresized( $tmp_img_comp , $pic, 0, 0, 0, 0, $new_width_comp , $new_height_comp , $width_comp , $height_comp  );
				$pth_comp  = site_url("images/temp/$picture_name");
				ob_start();
				$inp_comp  = imagejpeg( $tmp_img_comp  );
				$create_images_medium = ob_get_contents(); 
				return $create_images_medium;
			break;
			case "image/png":
				$pic = imagecreatefrompng($picture_tmp);
				$width_comp  = imagesx( $pic );
				$height_comp  = imagesy( $pic );
				$new_width_comp = $size;
				$new_height_comp  = floor( $height_comp * ( $size / $width_comp  ) );
				$tmp_img_comp  = imagecreatetruecolor( $new_width_comp , $new_height_comp  );
				$up_comp  = imagecopyresized( $tmp_img_comp , $pic, 0, 0, 0, 0, $new_width_comp , $new_height_comp , $width_comp , $height_comp  );
				$pth_comp  = site_url("images/temp/$picture_name");
				ob_start();
				$inp_comp  = imagepng( $tmp_img_comp  );
				$create_images_medium = ob_get_contents(); 
				return $create_images_medium;
			break;
			case "image/bmp":
				$pic = imagecreatefromjpeg($picture_tmp);
				$width_comp  = imagesx( $pic );
				$height_comp  = imagesy( $pic );
				$new_width_comp = $size;
				$new_height_comp  = floor( $height_comp * ( $size / $width_comp  ) );
				$tmp_img_comp  = imagecreatetruecolor( $new_width_comp , $new_height_comp  );
				$up_comp  = imagecopyresized( $tmp_img_comp , $pic, 0, 0, 0, 0, $new_width_comp , $new_height_comp , $width_comp , $height_comp  );
				$pth_comp  = site_url("images/temp/$picture_name");
				ob_start();
				$inp_comp  = imagewbmp( $tmp_img_comp  );
				$create_images_medium = ob_get_contents(); 
				return $create_images_medium;
			break;
			case "image/gif":
				$pic = imagecreatefromgif($picture_tmp);
				$width_comp  = imagesx( $pic );
				$height_comp  = imagesy( $pic );
				$new_width_comp = $size;
				$new_height_comp  = floor( $height_comp * ( $size / $width_comp  ) );
				$tmp_img_comp  = imagecreatetruecolor( $new_width_comp , $new_height_comp  );
				$up_comp  = imagecopyresized( $tmp_img_comp , $pic, 0, 0, 0, 0, $new_width_comp , $new_height_comp , $width_comp , $height_comp  );
				$pth_comp  = site_url("images/temp/$picture_name");
				ob_start();
				$inp_comp  = imagegif( $tmp_img_comp  );
				$create_images_medium = ob_get_contents(); 
				return $create_images_medium;
			break;
		}
	}
	
	protected function images_small($picture_tmp,$size,$picture_name,$picture_type){
		switch($picture_type){
			case "image/jpeg":
				$thumb = imagecreatefromjpeg($picture_tmp);
				$width = imagesx( $thumb );
				$height = imagesy( $thumb );
				$new_width = $size;
				$new_height = floor( $height * ( $size / $width ) );
				$tmp_img = imagecreatetruecolor( $new_width, $new_height );
				$up = imagecopyresized( $tmp_img, $thumb, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
				$pth = site_url("images/temp/$picture_name");
				ob_start();
				$inp = imagejpeg( $tmp_img );
				$create_images_small = ob_get_contents(); 
				return $create_images_small;
			break;
			case "image/png":
				$thumb = imagecreatefrompng($picture_tmp);
				$width = imagesx( $thumb );
				$height = imagesy( $thumb );
				$new_width = $size;
				$new_height = floor( $height * ( $size / $width ) );
				$tmp_img = imagecreatetruecolor( $new_width, $new_height );
				$up = imagecopyresized( $tmp_img, $thumb, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
				$pth = site_url("images/temp/$picture_name");
				ob_start();
				$inp = imagepng( $tmp_img );
				$create_images_small = ob_get_contents(); 
				return $create_images_small;
			break;
			case "image/bmp":
				$thumb = imagecreatefromjpeg($picture_tmp);
				$width = imagesx( $thumb );
				$height = imagesy( $thumb );
				$new_width = $size;
				$new_height = floor( $height * ( $size / $width ) );
				$tmp_img = imagecreatetruecolor( $new_width, $new_height );
				$up = imagecopyresized( $tmp_img, $thumb, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
				$pth = site_url("images/temp/$picture_name");
				ob_start();
				$inp = imagewbmp( $tmp_img );
				$create_images_small = ob_get_contents(); 
				return $create_images_small;
			break;
			case "image/gif":
				$thumb = imagecreatefromgif($picture_tmp);
				$width = imagesx( $thumb );
				$height = imagesy( $thumb );
				$new_width = $size;
				$new_height = floor( $height * ( $size / $width ) );
				$tmp_img = imagecreatetruecolor( $new_width, $new_height );
				$up = imagecopyresized( $tmp_img, $thumb, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
				$pth = site_url("images/temp/$picture_name");
				ob_start();
				$inp = imagegif( $tmp_img );
				$create_images_small = ob_get_contents(); 
				return $create_images_small;
			break;
		}
	}
}